fix(agent-core/mcp): sanitize recursive MCP JSON Schemas for Moonshot validator compatibility#2216
fix(agent-core/mcp): sanitize recursive MCP JSON Schemas for Moonshot validator compatibility#2216creatiVision wants to merge 13 commits into
Conversation
… max_tokens config fields
# Conflicts: # packages/agent-core/src/config/toml.ts # packages/agent-core/src/mcp/connection-manager.ts
…dation compatibility
… local running environment
🦋 Changeset detectedLatest commit: 424d2b5 The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 424d2b587f
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| ssh2@1.17.0>cpu-features: '-' | ||
| ssh2@1.17.0>nan: '-' | ||
|
|
||
| importers: |
There was a problem hiding this comment.
Restore the workspace overrides in the lockfile
pnpm-workspace.yaml still declares the two ssh2 overrides, but this lockfile no longer records them. The CI workflow at .github/workflows/ci.yml:26 runs pnpm install --frozen-lockfile; running that command against this tree stops before the build with ERR_PNPM_LOCKFILE_CONFIG_MISMATCH: The current "overrides" configuration doesn't match the value found in the lockfile. Regenerate the lockfile while preserving the workspace overrides.
Useful? React with 👍 / 👎.
| { | ||
| "name": "frontend-design", | ||
| "version": "1.1.0", | ||
| "description": "Frontend design skill for UI/UX implementation", |
There was a problem hiding this comment.
Declare the nested skills directory
Installing this plugin produces a manifest with no skills: parseManifest only uses the explicit skills field or falls back to a SKILL.md at the plugin root, while this plugin's only skill is under skills/frontend-design/SKILL.md. Consequently the newly added plugin installs without exposing its advertised frontend-design skill; add a "skills": "./skills/" entry.
Useful? React with 👍 / 👎.
| } | ||
| if (inferred.size === 1) return [...inferred][0]!; | ||
| if (inferred.size === 2 && inferred.has('integer') && inferred.has('number')) return 'number'; | ||
| return 'string'; |
There was a problem hiding this comment.
Preserve mixed enum value types
For a valid MCP schema such as enum: [1, "auto"], this fallback adds type: "string", making the numeric enum member invalid because JSON Schema applies type and enum together. Since McpConnectionManager applies this sanitizer to every discovered MCP tool before provider selection, providers that previously accepted mixed enums now receive a corrupted schema and may reject the request or prevent the model from selecting the numeric option.
Useful? React with 👍 / 👎.
| if (pathStr === '') { | ||
| return root; | ||
| } | ||
| const parts = pathStr.split('/'); |
There was a problem hiding this comment.
Decode JSON Pointer path segments
Local JSON Pointer segments must decode ~1 to / and ~0 to ~, but this split leaves them escaped before looking up the definition. A valid schema with $ref: "#/$defs/a~1b" and a definition named a/b therefore throws during tool discovery and can mark the MCP server failed; unescape each segment before indexing the schema.
Useful? React with 👍 / 👎.
| @@ -1,3 +1,3 @@ | |||
| auto-install-peers=true | |||
| engine-strict=true | |||
| engine-strict=false | |||
There was a problem hiding this comment.
Keep the repository's Node engine check enabled
When a developer runs pnpm install with Node older than 24.15.0, this setting now permits installation even though package.json and .nvmrc still require 24.15.0, deferring failures to later scripts that may rely on unsupported runtime behavior. The repository explicitly requires installs to fail on an unsatisfied Node engine, so this must remain enabled unless all version declarations and runtime requirements are intentionally lowered together.
AGENTS.md reference: AGENTS.md:L30-L33
Useful? React with 👍 / 👎.
Related Issue
Supersedes / continues the work from #830 and #1605.
Problem
Some MCP servers advertise tool input schemas that are valid standard JSON Schema but fail Moonshot's stricter “MFJS” validator, or crash Kimi during discovery:
$ref(e.g. self-referential$defs) causedMaximum call stack size exceededduring schema processing.itemsarrays (items: [{...}, {...}]) are rejected withitems must be an object.type(relying onenum/ structural keywords) are rejected withtype is not defined.Without sanitization, affected MCP servers fail to connect or poison inference requests with HTTP 400.
What changed
sanitizeMcpSchema(TS port of the legacy kosong JSON Schema interceptor) to:$refs (including circular roots)typeon property schemas where safeitemsinto{ anyOf: items }McpConnectionManagerafter tool discoverydisabled→enabled,max_tokens/max_output_tokens→max_output_sizeNotes for reviewers
engine-strictnoise from earlier branch merges may still need cleanup before merge (see bot review on this PR).prompt_cache_key400s — that is fix(agent-core): only send prompt_cache_key to official OpenAI endpoints #2203.Checklist